<%@ page import="cn.ruituo.service.StudentService" %>
<%@ page import="cn.ruituo.entity.Student" %>
<%@ page import="cn.ruituo.entity.Page" %>
<%@ page import="cn.ruituo.util.StrUtil" %><%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2021/3/22
  Time: 11:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生信息</title>
    <script src="js/jquery-3.4.1.min.js"></script>

</head>
<body>
<%--<%@include file="/checkLogin.jsp"%>--%>
<%
    int pageNo= StrUtil.toInt(request.getParameter("pageNo"),1);
    String sname=request.getParameter("sname");
    String qq=request.getParameter("qq");
    String tel=request.getParameter("telephone");
    Page<Student> paging = StudentService.service.paging(pageNo, 20, sname, qq, tel, null, null);
%>
<div align="center">
<form action="students.jsp" id="searchForm">
    <input type="hidden" name="pageNo" value="<%=pageNo%>">
    <input type="text" name="sname" placeholder="姓名" value="<%=sname==null?"":sname%>"/>
    <input type="text" name="qq" placeholder="qq号" value="<%=qq==null?"":qq%>"/>
    <input type="text" name="telephone" placeholder="手机号" value="<%=tel==null?"":tel%>"/>
    <input type="submit"/>
</form>
</div>
<table border="1" align="center" cellpadding="0" cellspacing="0">
    <tr bgcolor="#a9a9a9">
        <th>学号</th>
        <th>姓名</th>
        <th>手机号</th>
        <th>QQ</th>
        <th>性别</th>
        <th>入学时间</th>
        <th>邮件</th>
        <th>操作 </th>
    </tr>
    <%
        for (Student student : paging.getDatas()) {
    %>
    <tr>
        <td><%=student.getStuno()%></td>
        <td><%=student.getSname()%></td>
        <td><%=student.getTelephone()%></td>
        <td><%=student.getQq()%></td>
        <td><%=student.getSex()%></td>
        <td><%=student.getEnterdate()%></td>
        <td><%=student.getEmail()%></td>
        <td><a href="#">详情</a>&nbsp;<a href="toUpdateStudent.jsp?stuno=<%=student.getStuno()%>">修改</a>&nbsp;<a href="delStudent.jsp?stuno=<%=student.getStuno()%>" onclick="return confirm('您确定要删除嘛？')">删除</a>&nbsp; </td>
    </tr>
    <%}%>
</table>
<p align="center" id="page">
    <a href="students.jsp?pageNo=1" id="first">首页</a>
    <%
        if (pageNo>1){

    %>

    <a href="students.jsp?pageNo=<%=pageNo-1%>" id="prev">上一页</a>
    <%
        }
    %>
    <input type="number" min="1" value="<%=paging.getPageNo()%>" style="width: 60px">
    <input type="button" value="GO" id="go" style="width: 50px"/>
    <%
        if (pageNo<paging.getTotalPages()){
    %>
    <a href="students.jsp?pageNo=<%=pageNo+1%>" id="next">下一页</a>
    <%
        }
    %>
    <a href="students.jsp?pageNo=<%=paging.getTotalPages()%>" id="last"> 尾页</a>
</p>

<script>
    $(function () {
        $("#go").click(function () {
            var p=$(this).prev().val();
            if(p<=1)p=1;
            //window.location.href="students.jsp?pageNo="+p;
            $("#searchForm [name=pageNo]").val(p);
            $("#searchForm").submit();
            return false;
        });
        var pageNo=<%=pageNo%>;
        $("#page a#first").click(function () {
            $("#searchForm [name=pageNo]").val(1);
            $("#searchForm").submit();
            return false;//链接失效
        });
        $("#page a#prev").click(function () {
            $("#searchForm [name=pageNo]").val(--pageNo);
            $("#searchForm").submit();
            return false;//链接失效
        });
        $("#page a#next").click(function () {
            $("#searchForm [name=pageNo]").val(++pageNo);
            $("#searchForm").submit();
            return false;//链接失效
        });
        $("#page a#last").click(function () {
            pageNo=<%=paging.getTotalPages()%>;
            $("#searchForm [name=pageNo]").val(pageNo);
            $("#searchForm").submit();
            return false;//链接失效
        });
    });
</script>
</body>
</html>
